package com.xuecheng.manage_course.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xuecheng.framework.domain.course.ext.CourseInfo;
import com.xuecheng.framework.domain.course.request.CourseListRequest;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.QueryResult;
import com.xuecheng.manage_course.dao.CourseInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CourseInfoService {
    @Resource
    CourseInfoMapper courseInfoMapper;

    /**
     * 分页查询我的课程信息
     *
     * @param page              查询第几页
     * @param size              一页显示多少
     * @param courseListRequest 可以携带参数查询
     * @return
     */
    public QueryResponseResult<CourseInfo> findList(int page, int size, CourseListRequest courseListRequest) {
        PageHelper.startPage(page, size);
        Page<CourseInfo> courseInfoPage = courseInfoMapper.findCourseInfo(courseListRequest);
        QueryResult<CourseInfo> queryResult = new QueryResult<>();
        queryResult.setList(courseInfoPage.getResult());
        queryResult.setTotal(courseInfoPage.getTotal());
        return new QueryResponseResult<>(CommonCode.SUCCESS,queryResult);
    }
}
